-
Notifications
You must be signed in to change notification settings - Fork 58
feat: THIS
keyword
#1454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: THIS
keyword
#1454
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, mostly just some nits
compiler/plc_diagnostics/src/diagnostics/diagnostics_registry.rs
Outdated
Show resolved
Hide resolved
if function_context.linking_context.is_method() | ||
&& self.index.find_pou(type_name).is_some_and(|it| it.is_function_block()) | ||
{ | ||
let alloca = self.llvm.builder.build_alloca(param_pointer.get_type(), "this"); | ||
self.llvm.builder.build_store(alloca, param_pointer); | ||
index.associate_loaded_local_variable(type_name, "__THIS", alloca)?; | ||
} | ||
if function_context.linking_context.get_implementation_type() == &ImplementationType::FunctionBlock { | ||
let alloca = self.llvm.builder.build_alloca(param_pointer.get_type(), "this"); | ||
self.llvm.builder.build_store(alloca, param_pointer); | ||
index.associate_loaded_local_variable(type_name, "__THIS", alloca)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is actually neccessary because this
is essentially an alias on the function argument %0
, no? Specifically I would have assumed define void @FB_Test(%FB_Test* %0)
to become define void @FB_Test(%FB_Test* %this)
and then keep the codegen unchanged otherwise. However I wasn't able to find a quick solution for that without panicking so maybe theres another reason? Not a blocker though, can perhaps be improved in another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commenting without reading the entire PR, but I would go with ignoring THIS
all together in the codegen, the job of this is IMHO done with the resolver, the only exception to that is if we allow THIS^()
as in calling the function block in the method but this could then be handled on its own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should still resolve to the local variable in the POU, so technically no need for this. it's just a marker to resolve the annotation to local instead of global, so the resolving scope during the annotation phase will be local only or similar, and then the annotation will be that of the local variable, when codegen comes along, it finds the annotation of the local variable on the expression and generates that, again theoretical I did not do a deep dive into the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed we leave it as is for now and I created an issue (#1475) so that we don't forget about this
Co-authored-by: Volkan <[email protected]>
Co-authored-by: Volkan <[email protected]>
Co-authored-by: Volkan <[email protected]>
Add
THIS
keyword supportImplements validation for the
THIS
keyword, which represents a pointer to the current FUNCTION_BLOCK instance.Key points:
THIS
can only be used within:FUNCTION_BLOCK
implementationMETHODS
belonging to thatFUNCTION_BLOCK